package com.sheep.spark.rest.support;

import com.sheep.api.bean.ADSBBean;
import com.sheep.api.bean.ADSBResultBean;
import com.sheep.api.spark.SparkCommonService;
import com.sheep.api.util.JAXBUtils;
import com.sheep.spark.service.impl.SparkCommonImpl;
import org.apache.log4j.Logger;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 16-6-1
 * Time: 上午10:55
 * To change this template use File | Settings | File Templates.
 */
public class SparkSupport {
    private static final Logger logger = Logger.getLogger(SparkSupport.class);

    private static SparkCommonService sparkCommonService = null;

    public static SparkCommonService getSparkCommonService() {
        if (sparkCommonService == null) {
            sparkCommonService = new SparkCommonImpl();
        }
        return sparkCommonService;
    }

    public static String getADSBList(String year, String month, String date, String an,  String fi){
        String xml = "";
        try{
            long start = System.currentTimeMillis();
            List<ADSBBean> list = SparkSupport.getSparkCommonService().getADSBList(year, month, date, an, fi);
            long end = System.currentTimeMillis();
            if (list != null && list.size() > 0) {
                ADSBResultBean result = new ADSBResultBean();
                result.setList(list);
                result.setRunTime(end - start);
                xml = JAXBUtils.dtoToXmlString(result);
            }
        }   catch (Exception e){
            logger.error(e);
        }finally {
            return xml;
        }
    }


    public static String getADSBByCompress(String year, String month, String date, String an,  String fi){
        String xml = "";
        try{
            xml = SparkSupport.getSparkCommonService().getADSBDataByCompress(year, month, date, an, fi);
        }   catch (Exception e){
            logger.error(e);
            xml = null;
        }finally {
            return xml;
        }
    }


}
